<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:if test="#request.resultCount != null && #request.resultCount.size() > 0">
	<div style="width: 100%; color: red; text-align: center;">
		箱量数量不能少于有效柜号的数量 &nbsp; &nbsp; <a href="javascript:" onclick="$(this).parent().hide();" style="font-size: 12px; color:#858585;">隐藏</a>
	</div>
</s:if>
<table>
	<tr>
		<td style="border-right:1px solid #d0d0d0;" valign="top">
			<table id="boxNo" style="font-family: SimSun; margin-right: 5px;">
				<s:iterator var="b" value="#request.box" status="sta">
					<tr>
						<td><input type="text" id="<s:property value="#b" />" name="<s:property value="#b" />" value="<s:property value="#request.boxTypeCount[#sta.index]" />" class="boxAmount_txt"/></td>
						<td>
							<s:set var="t" value="'cts.work.box'+#b.substring(#b.length()-2)"></s:set>
							<s:property value="#request.boxTxt[#sta.index]"/>
							(<s:property value="#request.boxTxt[#sta.index]"/> <s:property value="getText(#t)" />)
						</td>
					</tr>
				</s:iterator>
				<tr>
					<td colspan="2" align="center"><a href="javascript:addBox()" class="fee_ok_right">保存箱量</a></td>
				</tr>
			</table>
		</td>
		<td valign="top">
			<table id="containerNoTable" class="tab1" cellpadding="0" cellspacing="0" style="width: 530px; margin-left: 10px;">
				<thead>
					<tr>
						<td width="90px">柜号</td>
						<td width="70px">封号</td>
						<td>箱型</td>
						<td>件数</td>
						<td>毛重</td>
						<td>体积</td>
						<td>通风</td>
						<td>发电机</td>
						<td>温度</td>
						<td width="55px">操作</td>
					</tr>
				</thead>
				<s:iterator value="#request.cnList" status="sta">
				<tr <s:if test="#sta.index % 2 == 0">class="tr1"</s:if> boxType="<s:property value="#request.box[@java.lang.Integer@parseInt(typeAndSize)]"/>">
					<td>
						<input type="text" id="cntrNo<s:property value="#sta.index" />" name="containerNo.cntrNo" value="<s:property value="cntrNo" />" v_tips="notnull,cntrNO" style="width: 95%;" class="input_normal"/>
						<input type="hidden" id="cnId<s:property value="#sta.index" />" name="containerNo.id" value="<s:property value="id" />">
					</td>
					<td><input type="text" id="sealNo<s:property value="#sta.index" />" name="containerNo.sealNo" value="<s:property value="sealNo" />" class="input_normal"/></td>
					<td>
						<s:property value="#request.boxTxt[@java.lang.Integer@parseInt(typeAndSize)]"/>
						<input type="hidden" id="typeAndSize<s:property value="#sta.index" />" name="containerNo.typeAndSize" value="<s:property value="typeAndSize" />">
					</td>
					<td><input type="text" id="count<s:property value="#sta.index" />" v_tips="nullable,i" name="containerNo.count" value="<s:property value="count" />" class="input_normal"/></td>
					<td><input type="text" id="grossWeight<s:property value="#sta.index" />" v_tips="nullable,pnumber" name="containerNo.grossWeight" value="<s:property value="grossWeight" />" class="input_normal"/></td>
					<td><input type="text" id="volume<s:property value="#sta.index" />" v_tips="nullable,pnumber" name="containerNo.volume" value="<s:property value="volume" />" class="input_normal"/></td>
					<td width="45px;">
						<select id="hasAirintake<s:property value="#sta.index" />" name="containerNo.hasAirintake" pass="1" class="select_normal">
							<option value="0">否</option>
							<option value="1" <s:property value="hasAirintake == 1 ? 'selected' : ''" />>是</option>
						</select>
					</td>
					<td width="45px;">
						<select id="hasDynamo<s:property value="#sta.index" />" name="containerNo.hasDynamo" pass="1" class="select_normal">
							<option value="0">否</option>
							<option value="1"<s:property value="hasDynamo == 1 ? 'selected' : ''" />>是</option>
						</select>
					</td>
					<td><input id="temperature<s:property value="#sta.index" />" v_tips="nullable,pnumber" type="text" name="containerNo.temperature" value="<s:property value="temperature" />" class="input_normal"/></td>
					<td>
						<a href="javascript:" onclick="saveBox(this)" class="fee_ok"></a>
						<a href="javascript:" onclick="delBox(this,'<s:property value="id" />')" class="fee_del"></a>
					</td>
				</tr>
				</s:iterator>
			</table>
		</td>
	</tr>
</table>
<script>
var firstLoad = true;  //记录是否刚加载

function setBoxAmount(text){
	if(text != ''){
		if($('#boxSpan').length == 0){
			$('#boxTitle').after("<span id='boxSpan'></span><br><br style='line-height:10px;'>");
		}
		$('#boxSpan').text(text)
	}else{
		$('#boxSpan').nextAll('br:lt(2)').remove();
		$('#boxSpan').remove();
	}
}
function saveBox(obj){
	var resultFn = function(result){
		if(result != 'ok'){
			alert('保存失败');
			return false;
		}else{
			return true;
		}
	}
	saveOrEditTr(obj,'saveBoxAmount',resultFn)
}
//删除箱量
function delBox(obj,id){
	if(!window.confirm('确认要删除？')) return;
	$.post('cts/delBoxAmount?cnId='+id,null,function(result){
		var boxAmount = result.substring(0,result.length-2);
		var result = result.substring(result.length-2);
		if(result == 'ok'){
			var boxCount = $('#'+$(obj).parents('tr:first').attr('boxType'));
			boxCount.val(boxCount.val() - 1);
			$(obj).parents('tr:first').find('input:text').each(function(){
				$('#tipsDiv_'+this.id).hide();
			})
			$(obj).parents('tr:first').remove();
			setBoxAmount(boxAmount);
			$('#containerNoTable tr:gt(0)').each(function(i){
				if(i%2 == 0) this.className = 'tr1'
				else this.className = '';
			})
		}else{
			alert('删除失败');
		}
	})
}
//添加箱量
function addBox() {
	$('.tips_div').hide();
	var param = $('#boxNo').find('input:text').serialize()+'&workId='+$('#workId').val();
	$('#boxAmountDiv').find('.popdiv_content').append("<img src='"+prefix+"images/loading.gif' class='loading'/>");
	$.post('cts/addBoxAmount',param,function(result){
		if(result.indexOf('containerNoTable') > 0){
			$('#boxAmountDiv').find('.popdiv_content').html(result);
		}else{
			openPopDiv('boxAmountDiv','showBoxAmount?workId=<s:property value="work.id" />')
			alert('添加失败');
		}
	})
}

function boxLoad(){
	if(!firstLoad) return;
	$('#containerNoTable input:text').each(function(){
		$(this).validateTips();
	})
	$('#containerNoTable tr .fee_ok').each(function(){
		saveOrEditTr(this);
	})
	var boxAmount = "<s:property value="work.boxAmount" />";
	setBoxAmount(boxAmount);
	firstLoad = false;
}
boxLoad();
</script>